// 390. 消除游戏
/**
 * @param {number} n
 * @return {number}
 */
var lastRemaining = function (n) {
    let start = 1, deep = 0
    while (n > 1) {
        if (n & 1) {
            start += 2 ** deep
            n = (n - 1) / 2
        } else {
            // 只有deep为奇数的时候才会删除第一个
            !(deep & 1) && (start += 2 ** deep)
            n = n / 2
        }
        deep++
    }
    return start
};
lastRemaining(9)